//
// This file is part of cpp-lib, a library of C++ functions and classes.
// Cpp-lib is copyright (C) 2004 and onwards, The CPL Interest Group.
// 
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2.1 of the License, or (at
// your option) any later version.
// 
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this library (see the file COPYING); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307  USA
//
// $Id$
//

namespace {

inline int socketclose( socketfd_t const s ) { return closesocket( s ) ; }


const socketfd_t invalid_socket = INVALID_SOCKET ;

// typedef int socklen_t ;

} // anonymous namespace


#define SOCKET_ERROR_MSG cpl::detail_::last_error_message()

// 
// Stuff existing on UNIX but not on Windows.
//

#define h_errno WSAGetLastError()
#define ECONNREFUSED WSAECONNREFUSED


namespace {

struct winsock_initializer {

  winsock_initializer() {

    const WORD wVersionRequested = MAKEWORD( 2 , 2 ) ;
    WSADATA wsaData ;
  
	// std::cout << "WSAStartup()\n" ;

    if( WSAStartup( wVersionRequested, &wsaData ) )
    { cpl::util::die( "couldn't find suitable winsock.dll" ) ; }

  }

  ~winsock_initializer() {
  
    // std::cout << "WSACleanup()\n" ;
    WSACleanup() ;

  }

} william_h_gates_iii ;

} // anonymous namespace
